package com.train.order.core.config.sentinel;

import com.alibaba.csp.sentinel.transport.config.TransportConfig;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class SentinelConfig {

    @Value("${spring.cloud.sentinel.transport.dashboard}")
    private String dashboard;

    @Value("${spring.cloud.sentinel.transport.port}")
    private String serverPort;

    @PostConstruct
    public void initSentinel() {
        System.setProperty(TransportConfig.CONSOLE_SERVER, dashboard); // Sentinel Dashboard配置
        System.setProperty(TransportConfig.SERVER_PORT, serverPort); //客户端和服务端交互的端口

        // 打印配置信息
        log.info("Sentinel Dashboard: " + System.getProperty(TransportConfig.CONSOLE_SERVER));
//        log.info("Sentinel Client IP: " + System.getProperty(TransportConfig.HEARTBEAT_CLIENT_IP));
        log.info("Sentinel Client Port: " + System.getProperty(TransportConfig.SERVER_PORT));
    }
}
